class UserController < ApplicationController
    include AuthenticatedSystem
    before_filter :login_required, :except => 'exist'
    
    def config
        @user = User.find(session[:user])
        @profile = @user.profile
        if @profile.nil?
            p = Profile.new
            p.user_id = session[:user]
            p.save
        end
        if request.post?
            @user.update_attributes(params[:user])
            @profile.update_attributes(params[:profile])
            flash[:notice] = "信息已成功更新!"
            redirect_to :action => 'config'
        end
    end
    
    def exist
        if request.xhr?
            user = User.find_by_login(params[:login])
            if user
                render :text => 'true'
            else
                render :text => 'false'
            end
        else
            redirect_to :controller => 'index'
        end
    end
end
